package com.power.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.power.domain.Area;
import com.power.mapper.AreaMapper;
import com.power.service.AreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import com.power.constant.StoreConstants;

import java.util.List;

/**
* @author dingchunlin
* @description 针对表【area】的数据库操作Service实现
* @createDate 2024-07-10 15:12:13
*/
@Service
@CacheConfig(cacheNames = "com.power.service.impl.AreaServiceImpl")
public class AreaServiceImpl extends ServiceImpl<AreaMapper, Area> implements AreaService{

    @Autowired
    private AreaMapper areaMapper;

    /**
     * 查询所有地区信息
     * @return List<Area>
     */
    @Override
    @Cacheable(key = StoreConstants.ALL_AREA_KEY)
    public List<Area> queryAllAreaList() {
        List<Area> areaList = areaMapper.selectList(null);
        return areaList;
    }

    /**
     * 根据父级id查询子级地区信息
     *
     * @param pid 父级id
     * @return List<Area>
     */
    @Override
    public List<Area> queryAreaListByPid(Long pid) {
        List<Area> areaList = areaMapper.selectList(new LambdaQueryWrapper<Area>()
                .eq(Area::getParentId, pid));
        return areaList;
    }
}




